
"""
Given two lists of words and two indexes in a string finds the least 
bounding box between the first list of words and the second, containing
the interval defined by the two indexes in the middle.
"""
def lbbox(string, llist, rlist, lindex, rindex):
    """
    TODO: Rudimentary finding of indexes, need to optimize this
    """
    bblindex = 0
    bbrindex = len(string)
    if llist:
        for word in llist:
            prevbblindex = string.rfind(word, 0, lindex)
            prevbblindex += len(word)
            if prevbblindex < lindex and prevbblindex > bblindex:
                bblindex = prevbblindex
    if rlist:
        for word in rlist:
            prevbbrindex = string.rfind(word, rindex, len(string))
            if prevbbrindex > rindex and prevbbrindex < bbrindex:
                bbrindex = prevbbrindex
    return (bblindex, bbrindex)

"""
Searches string for every s in list. No more than two s in list are allowed in string,
in which case the function returns -1, otherwise it returns the index where s is located.
"""
def search_for_uniques(string, list):
    index = -1
    for s in list:
        nindex = string.find(s, 0, len(string))
        if index >= 0:
		if nindex >= 0:
			return -1
	else:
            index = nindex
    return index
            

    

    
    
    
